﻿using System;

namespace WikiDoc
{
    /// <summary>
    /// 
    /// </summary>
    public class WikiLine
    {
        /// <summary>
        /// 初始化 <see cref="WikiLine"/> 类的新实例。
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="line">The line.</param>
        protected WikiLine(LineType type, string line)
        {
            _Type = type;
            _Line = line;
        }

        private LineType _Type;
        /// <summary>
        /// 行的类型
        /// </summary>
        public LineType Type
        {
            get { return _Type; }
            protected set { _Type = value; }
        }

        private string _Line;
        /// <summary>
        /// Gets the line.
        /// </summary>
        /// <value>The line.</value>
        public string Line
        {
            get { return _Line; }
            protected set { _Line = value; }
        }

        /// <summary>
        /// Constructs the code end line.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <returns></returns>
        public static WikiLine ConstructCodeEndLine(string line)
        {
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }

            return new WikiLine(LineType.CodeEnd, line);
        }


        private static readonly WikiLine _EofLine = new WikiLine(LineType.Eof, null);

        /// <summary>
        /// Get the EofLine
        /// </summary>
        /// <returns></returns>
        public static WikiLine EofLine
        {
            get { return _EofLine; }
        }

        private static readonly WikiLine _EmptyLine = new WikiLine(LineType.Empty, string.Empty);

        /// <summary>
        /// get the Empty line.
        /// </summary>
        /// 
        /// <returns></returns>
        public static WikiLine EmptyLine
        {
            get { return _EmptyLine; }
        }

        /// <summary>
        /// Construct a Normal line.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <returns></returns>
        public static WikiLine ConstructNormalLine(string line)
        {
            if (line == null) throw new ArgumentNullException("line");

            return new WikiLine(LineType.Normal, line);
        }

        /// <summary>
        /// Resets as.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="line">The line.</param>
        /// <returns></returns>
        internal WikiLine ResetAs(LineType type, string line)
        {
            _Type = type;
            _Line = line;

            return this;
        }
    }

}
